//
// File: smart_bridge.h
//
// Code generated for Simulink model 'smart_bridge'.
//
// Model version                  : 1.51
// Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
// C/C++ source code generated on : Wed Sep 15 14:05:34 2021
//
// Target selection: ert.tlc
// Embedded hardware selection: Generic->Unspecified (assume 32-bit Generic)
// Code generation objectives: Unspecified
// Validation result: Not run
//
#ifndef RTW_HEADER_smart_bridge_h_
#define RTW_HEADER_smart_bridge_h_
#include <stddef.h>
#include "rtwtypes.h"
#include "slros_initialize.h"
#include "smart_bridge_types.h"

// Child system includes
#include "get_msg_from_smart.h"
#include "set_msg_to_smart.h"
#include "tcp_client_init.h"

// Macros for accessing real-time model data structure
#ifndef rtmGetErrorStatus
#define rtmGetErrorStatus(rtm)         ((rtm)->errorStatus)
#endif

#ifndef rtmSetErrorStatus
#define rtmSetErrorStatus(rtm, val)    ((rtm)->errorStatus = (val))
#endif

// user code (top of header file)
// System '<Root>/tcp_client_init'
#include <iostream>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include <errno.h>
#define TCP_TX_BUF_MAX                 40
#define TCP_RX_BUF_MAX                 40
#define DATA_WIDTH                     4
#define APP_NULL                       0
#define PTCL_DATA_MAX                  8
#define NET_HEAR                       0
#define NET_DTX_1                      1
#define NET_DTX_2                      2
#define NET_DTX_3                      3
#define NET_DTX_4                      4
#define NET_DTX_5                      5
#define NET_DTX_6                      6
#define NET_DTX_7                      7
#define NET_DTX_8                      8
#define NET_CHKS                       9
#define NET_FRAME_HEADER               '$'

extern int clitfd;
extern uint8_T tcp_txd_buf[TCP_TX_BUF_MAX];
extern uint8_T tcp_rxd_buf[TCP_RX_BUF_MAX];
void net_tcp_open(void);
void net_tcp_close(void) ;
float net_get_rxd(uint8_t index);
void net_set_txd(uint8_t index, float data);
uint8_t net_chkmsg(uint8_t msg[TCP_RX_BUF_MAX]) ;

// Block signals (default storage)
typedef struct {
  SL_Bus_smart_bridge_smart_msgs_ptcl In1;// '<S10>/In1'
  SL_Bus_smart_bridge_smart_msgs_ptcl b_varargout_2;
} B_smart_bridge_T;

// Block states (default storage) for system '<Root>'
typedef struct {
  ros_slroscpp_internal_block_P_T obj; // '<S7>/SinkBlock'
  ros_slroscpp_internal_block_S_T obj_m;// '<S2>/SourceBlock'
  uint8_T is_active_c3_smart_bridge;   // '<Root>/Chart'
  uint8_T is_c3_smart_bridge;          // '<Root>/Chart'
  uint8_T S1;                          // '<Root>/Chart'
  uint8_T S2;                          // '<Root>/Chart'
} DW_smart_bridge_T;

// Parameters (default storage)
struct P_smart_bridge_T_ {
  SL_Bus_smart_bridge_smart_msgs_ptcl Constant_Value;// Computed Parameter: Constant_Value
                                                        //  Referenced by: '<S6>/Constant'

  SL_Bus_smart_bridge_smart_msgs_ptcl Out1_Y0;// Computed Parameter: Out1_Y0
                                                 //  Referenced by: '<S10>/Out1'

  SL_Bus_smart_bridge_smart_msgs_ptcl Constant_Value_a;// Computed Parameter: Constant_Value_a
                                                          //  Referenced by: '<S2>/Constant'

  SL_Bus_smart_bridge_smart_msgs_ptcl smart_msg_InitialValue;
                                   // Computed Parameter: smart_msg_InitialValue
                                      //  Referenced by: synthesized block

  uint8_T s_Y0;                        // Computed Parameter: s_Y0
                                          //  Referenced by: '<S5>/s'

  uint8_T s_Y0_o;                      // Computed Parameter: s_Y0_o
                                          //  Referenced by: '<S4>/s'

  uint8_T chart_s1_InitialValue;    // Computed Parameter: chart_s1_InitialValue
                                       //  Referenced by: synthesized block

  uint8_T chart_s2_InitialValue;    // Computed Parameter: chart_s2_InitialValue
                                       //  Referenced by: synthesized block

  P_get_msg_from_smart_smart_br_T get_msg_from_smart;// '<S4>/get_msg_from_smart' 
  P_set_msg_to_smart_smart_brid_T set_msg_to_smart;// '<S5>/set_msg_to_smart'
};

// Real-time Model Data Structure
struct tag_RTM_smart_bridge_T {
  const char_T *errorStatus;
};

// Block parameters (default storage)
#ifdef __cplusplus

extern "C" {

#endif

  extern P_smart_bridge_T smart_bridge_P;

#ifdef __cplusplus

}
#endif

// Block signals (default storage)
#ifdef __cplusplus

extern "C" {

#endif

  extern B_smart_bridge_T smart_bridge_B;

#ifdef __cplusplus

}
#endif

// Block states (default storage)
extern DW_smart_bridge_T smart_bridge_DW;

//
//  Exported Global Signals
//
//  Note: Exported global signals are block signals with an exported global
//  storage class designation.  Code generation will declare the memory for
//  these signals and export their symbols.
//

#ifdef __cplusplus

extern "C" {

#endif

  extern boolean_T tx_enb;             // '<Root>/Chart'
  extern SL_Bus_smart_bridge_smart_msgs_ptcl ros_msg;// '<S9>/Data Store Read'

#ifdef __cplusplus

}
#endif

//
//  Exported States
//
//  Note: Exported states are block states with an exported global
//  storage class designation.  Code generation will declare the memory for these
//  states and exports their symbols.
//

extern SL_Bus_smart_bridge_smart_msgs_ptcl smart_msg;// Simulink.Signal object 'smart_msg' 
extern uint8_T chart_s1;               // Simulink.Signal object 'chart_s1'
extern uint8_T chart_s2;               // Simulink.Signal object 'chart_s2'

#ifdef __cplusplus

extern "C" {

#endif

  // Model entry point functions
  extern void smart_bridge_initialize(void);
  extern void smart_bridge_step(void);
  extern void smart_bridge_terminate(void);

#ifdef __cplusplus

}
#endif

// Real-time Model object
#ifdef __cplusplus

extern "C" {

#endif

  extern RT_MODEL_smart_bridge_T *const smart_bridge_M;

#ifdef __cplusplus

}
#endif

//-
//  The generated code includes comments that allow you to trace directly
//  back to the appropriate location in the model.  The basic format
//  is <system>/block_name, where system is the system number (uniquely
//  assigned by Simulink) and block_name is the name of the block.
//
//  Use the MATLAB hilite_system command to trace the generated code back
//  to the model.  For example,
//
//  hilite_system('<S3>')    - opens system 3
//  hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
//
//  Here is the system hierarchy for this model
//
//  '<Root>' : 'smart_bridge'
//  '<S1>'   : 'smart_bridge/Chart'
//  '<S2>'   : 'smart_bridge/subscribe user message  '
//  '<S3>'   : 'smart_bridge/tcp_client_init'
//  '<S4>'   : 'smart_bridge/Chart/get_msg'
//  '<S5>'   : 'smart_bridge/Chart/set_msg'
//  '<S6>'   : 'smart_bridge/Chart/get_msg/Blank Message'
//  '<S7>'   : 'smart_bridge/Chart/get_msg/Publish1'
//  '<S8>'   : 'smart_bridge/Chart/get_msg/get_msg_from_smart'
//  '<S9>'   : 'smart_bridge/Chart/set_msg/set_msg_to_smart'
//  '<S10>'  : 'smart_bridge/subscribe user message  /Enabled Subsystem'

#endif                                 // RTW_HEADER_smart_bridge_h_

//
// File trailer for generated code.
//
// [EOF]
//
